
// ************************************
// * GStore - Inventory System - thomasfn *
// ************************************
// SHARED

Msg( "[GSTORE] Loading...\n" )

function AccessorFuncCB( tbl, var, acc, typ, onchange )
	local function Set( self, val )
		if (typ == FORCE_BOOL) then val = tobool( val ) end
		if (typ == FORCE_NUMBER) then val = tonumber( val ) end
		if (typ == FORCE_STRING) then val = tostring( val ) end
		self[ var ] = val
		onchange( self, var, val )
	end
	local function Get( self )
		return self[ var ]
	end
	tbl[ "Set" .. acc ] = Set
	tbl[ "Get" .. acc ] = Get
end

local oldPlayer = Player
function Player( id )
	if (SinglePlayer()) then return player.GetAll()[1] end
	return oldPlayer( id )
end

if (SERVER) then

	include( "init.lua" )
	include( "inventory.lua" )
	
	AddCSLuaFile( "core.lua" )
	AddCSLuaFile( "cl_init.lua" )
	AddCSLuaFile( "cl_vgui.lua" )
	AddCSLuaFile( "cl_gui.lua" )

end

if (CLIENT) then

	include( "cl_init.lua" )
	include( "cl_vgui.lua" )
	include( "cl_gui.lua" )
	
	require( "gstore_ui" )

end

require( "gstore" )
if (!gstore) then

	ErrorNoHalt( "[GSTORE] Module failed to load!\n" )
	return

end

gstore.LoadBase( "base_item.lua" )
gstore.LoadFactoryDirect( "base_container.lua" )
gstore.LoadAll( GM.Folder .. "/gamemode/gstore/factories" )

GSTORE_ITEMRANGE = 1024
GSTORE_USERANGE = 64
GSTORE_TICKRATE = 5
GSTORE_HUD_DISTANCE = 256
GSTORE_HUD_THICKNESS = 2

Msg( "[GSTORE] Loaded!\n" )